﻿/****************************************************************
 * Copyright (c) 2010-2013 Besture All Rights Reserved.
 * 
 * File Name:		QueryDal 
 * 
 * Created:		2013-8-28 19:01:29
 * Original Author:	nitao 
 * 
 * ------------------------------------------------------------
 * MODIFICATION HISTORY
 * ------------------------------------------------------------
 * When			Who		Why
 * ------------------------------------------------------------
 * 
 *
 ****************************************************************/

using System;
using System.Data;
using System.Data.Common;
using System.Text;
using Besture.Common;

namespace Besture.Dal
{
    public class QueryDal : BaseDataAccess
    {
        /// <summary>
        /// 获取全部数据
        /// </summary>
        /// <returns></returns>
        public DataTable GetTable(string sql)
        {
            try
            {
                DbCommand ldcDBCommand = base.GetCommand(sql);
                DataTable dt = base.GetDataSet(ldcDBCommand).Tables[0];
                return dt;
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="tableName">表名称</param>
        /// <param name="ids">主键值集合</param>
        /// <returns></returns>
        public int DeleteList(string tableName,string ids)
        {
            int iTmp = -1;
            try
            {
                StringBuilder updateSql = new StringBuilder();
                updateSql.Append("exec('DELETE FROM " + tableName);
                updateSql.Append(" WHERE ");
                updateSql.Append(" ID in ('+@ID+') ')");
                DbCommand ldcDBCommand = base.GetCommand(updateSql.ToString());
                base.SetParameter(ldcDBCommand, "@ID", DbType.String, ids);
                iTmp = base.ExecuteNonQuery(ldcDBCommand);
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return iTmp;
        }



    }
}
